#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include "header.h"
#include "File_System_Operations.h" // included header here to  obtain the function declaration
#include "File_Operations.h"
#include "hash.h"

struct Main_header MAN;
struct file_descriptor FDESC;
FILE *vfptr;


void main(char * argv, int argc) {

	int i;
	struct Free_list *start,*flist=NULL;
	//struct file_descriptor fdes[100];


	printf("****************VFS File Sytem**********************\n");
	printf("Necessary commands for implementing it are below:\n");
	printf("1.for creating a new VFS we use : 		create_vfs filename size\n");
	printf("2.For mounting the file sytem on root we use :  mount_vfs path\n");
	printf("3.For unmounting we use : 			unmount_vfs filename\n");
	printf("\n$>");

	do {
	 char input[50];
	 gets(input);
	 if(strstr( input,"create_vfs") > 0 )
		{
		
		char *name;
		int s;
		name=strtok(input," ");
		name=strtok(NULL," ");
		s=atoi(strtok(NULL," "));
		char file_name[30];
		strcpy(file_name,name);
		strcpy(MAN.vf_File_Label,file_name) ;
		/*MAN.Max_fd=s/1024;
		int h=(sizeof(MAN)+(sizeof(FDESC)*MAN.Max_fd));
		printf(" Size of man:%d\n",sizeof(MAN));
		printf(" Size of fdesc:%d\n",sizeof(FDESC));
		MAN.Max_fd=(s-h)/1024;
		MAN.fd_in_use=0;*/
		int y=create_vfs(file_name,s);
		initialize();
		printf("\n");
		printf("VFS11 #");
	
		
	}
	 else if(strstr(input,"mount_vfs") > 0 ) {
	 	char *name;
		name=strtok(input," ");
		name=strtok(NULL," ");
		mount_vfs(name);	
		printf("\n***************FILE OPERATIONS**********************\n");
		printf("Necessary commands for implementing it are below:\n");
		printf("1.For creating new file(Enter $ as EOF after data): 	create dest_dir_name file_name data_to_be_stored\n");
		printf("2.To view the contents file : 	listfile file_path\n");
		printf("3.To update file contents:	update file_path data\n");
		printf("4.To delete a file:		rm file_path\n");
		printf("5.To move file :	        mv source_file_path dest_file_path\n");
		printf("6.To copy file:			copy source_file/dir_path dest_file/dir_path\n");
		printf("7.To export to hard disk:	Export file_path\n");
		printf("VFS11 # %s",name);
	}
	 else if(strstr(input,"create")>0) { //create a file
			int flg;
			char *dir_name,*f_name;
			char *data;	//all usr file will be in /vf11/usr
			  dir_name=strtok(input," ");
			  dir_name=strtok(NULL," ");		
			  f_name=strtok(NULL," ");
			  data=strtok(NULL,"$");
			  flg=create(dir_name,f_name,data);
			  	
	}
	else if(strcmp(input,"unmount") == 0 ) {
		char *name;
		name=strtok(input," ");
		name=strtok(NULL," ");
	       int i=unmount_vfs(name);
		if(i==1)
			printf("Successfully unmounted"); 
	}
	else if(strcmp(input,"exit") == 0 ) break;
	else
		{
              printf("Command doesnt exits\n");
		printf("VFS11 #");
}
	}while(1);
}
